'use strict';
var calculate_median = function(collection){
    let arr_even = collection.filter((value,index)=>{
        if(index %2 !== 0){
            return value ;
        }
    }).sort((a,b)=>(a-b));
    let arr_odd  = collection.filter((value,index)=>{
        if(index %2 === 0){
            return value ;
        }
    }).sort((a,b)=>(a-b));
    if(arr_even.length %2 ===0){
        return arr_odd[parseInt(arr_even.length/2)] ;
    }else{
        return arr_even[parseInt(arr_even.length/2)] ;
    }
};
module.exports = calculate_median;
// var collection_a = [1, 2, 3, 4, 5, 6];
// var collection_b = [1, 2, 3, 4, 5, 6, 7, 8, 9];
// console.log(calculate_median(collection_a));
// console.log(calculate_median(collection_b));